import {
  ADD_GOOD_COUNT, ADD_GOOD,CHANGE_ALL_CHECK,CHANGE_ONE_CHECK
} from "./mutations-types";

export default {
  addCart({commit, state}, payload) {
    return new Promise((resolve, reject)=>{
      let good = state.cartList.find(item => item.pid === payload.pid)
      if (good) {
        //重复加入
        commit(ADD_GOOD_COUNT, good)
        resolve('同样商品+1')
      } else {
        //第一次加入
        payload.count = 1;
        payload.check = true
        commit(ADD_GOOD, payload)
        resolve('新增商品')

      }
    })
  },
  selectAll({commit,state}, payload) {
    commit(CHANGE_ALL_CHECK,payload)
  },
  changeOneCheck({commit,state}, payload){
    commit(CHANGE_ONE_CHECK,payload)
  }

}
